import 'package:flutter/material.dart';

import 'package:get/get.dart';
import 'package:getwidget/components/avatar/gf_avatar.dart';
import 'package:getwidget/components/drawer/gf_drawer.dart';
import 'package:getwidget/components/drawer/gf_drawer_header.dart';

import '../controllers/gfdrawer_controller.dart';

class GfdrawerView extends GetView<GfdrawerController> {
  String avatarUrl = 'https://i0.hdslb.com/bfs/face/d857929b564a8aa7c63ac40b32f952841928e2d9.jpg@128w_128h_1o.webp';
  String bgPath = 'assets/images/bg_drawer.jpg';
  String avatarPath = 'assets/images/flutter.jpg';

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        // leading: ,
        title: Text('抽屉菜单'),
        centerTitle: true,
        actions: [
          InkWell(
            onTap: () {
              Get.back();
            },
            child: Icon(Icons.home),
          ),
          SizedBox(width: 10,)
        ],
      ),
      drawer: _renderDrawer(),
      body: Center(
        child: Text(
          'GFDrawer',
          style: TextStyle(fontSize: 20),
        ),
      ),
    );
  }

  Widget _renderDrawer() {
    return GFDrawer(
      child: ListView(
        padding: EdgeInsets.zero,
        children: <Widget>[
          GFDrawerHeader(
            decoration: BoxDecoration(
              // 背景图片
              image: DecorationImage(
                fit: BoxFit.cover,
                image: AssetImage(bgPath)
              )
            ),
            currentAccountPicture: GFAvatar(
              radius: 80.0,
              backgroundImage: NetworkImage(avatarUrl),
            ),
            otherAccountsPictures: <Widget>[
              Image(
                image: AssetImage(avatarPath),
                fit: BoxFit.cover,
              ),
              GFAvatar(
                child: Text("ab"),
              )
            ],
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Text('初六'),
                Text('whoicliu@163.com'),
              ],
            ),
          ),
          ListTile(
            title: Text('Item 1'),
            onTap: null,
          ),
          ListTile(
            title: Text('Item 2'),
            onTap: null,
          ),
        ],
      ),
    );
  }
}
